<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-input v-model="query.phone" clearable placeholder="输入手机号搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
    <el-select v-model="query.template_type" clearable placeholder="模板类型" class="filter-item" style="width: 200px">
      <el-option v-for="item in dic_list.template_type" :key="item.dict_code" :label="item.label" :value="item.dict_code"/>
    </el-select>
    <el-button class="filter-item" size="mini" type="primary" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <!-- 新增 -->
    <div style="display: inline-block;margin: 0px 2px;">
      <el-button
        v-if="checkPermission(['admin','MessageTemplet_all','MessageTemplet_create'])"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="add">新增</el-button>
      <eForm ref="form" :is-add="true" :dic_list="dic_list"/>
    </div>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission' // 权限判断函数
import { parseTime } from '@/utils/index'
import eForm from './form'
// 查询条件
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    },
    dic_list: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      downloadLoading: false
    }
  },
  methods: {
    checkPermission,
    add() {
      const _this = this.$refs.form
      _this.form = {
        re_count: 3,
        send_time: '08:00',
        status: 1 }
      _this.dialog = true
    },
    toQuery() {
      this.$parent.page = 1
      this.$parent.init()
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'createTime') {
          return parseTime(v[j])
        } else {
          return v[j]
        }
      }))
    }
  }
}
</script>
